package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysLoginLogService;
import com.example.demo.dto.log.SysLoginLogPageReqVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RequestMapping(value = "/system/sys_login_log")
@RestController
public class SysLoginLogController extends BaseAdminController {

    @Resource
    private ISysLoginLogService sysLoginLogService;

    @GetMapping("/list")
    public AjaxRes list(SysLoginLogPageReqVO sysLoginLogPageReqVO) {
        return AjaxRes.success(sysLoginLogService.list(sysLoginLogPageReqVO));
    }

    @DeleteMapping("/delete/{logIds}")
    @Log(title = "删除登录日志", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("logIds") Long[] logIds) {
        return toAjax(sysLoginLogService.deleteLoginLog(logIds));
    }

    @DeleteMapping("/clear")
    @Log(title = "清空登录日志", businessType = BusinessType.CLEAR)
    public AjaxRes clear(){
        sysLoginLogService.clearLoginLog();
        return success();
    }
}
